home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF CDFconvert.
- *
- * Version 2.0, 4-Mar-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 24-Jan-91, H Leckner Original version (for CDF V2.0).
- * V2.0 4-Mar-92, J Love IBM PC port (major changes).
- *
- ******************************************************************************/
-
- #include "cdfdist.h"
- #include "cdfcvt.h"
-
- /******************************************************************************
- * Macro constants.
- ******************************************************************************/
-
- #define SOURCEformat (-1)
- #define SOURCEmajority (-1)
- #define SOURCEencoding (-1)
-
- /******************************************************************************
- * Global variables.
- ******************************************************************************/
-
- Boolean useSkeletonCDF;
- Boolean mLog;
- long dstFormat = SOURCEformat;
- long dstMajority = SOURCEmajority;
- long dstEncoding = SOURCEencoding;
- long numDims, dimSizes[CDF_MAX_DIMS];
- long srcFormat, srcMajority, srcEncoding;
- CDFid srcId, dstId, sktId;
-
- /******************************************************************************
- * Online help text.
- ******************************************************************************/
-
- static char *instructions[] = {
- #if defined(vms)
- "Usage: $ CDFCONVERT [/SKELETON=<cdf-path>] [/[NO]LOG]",
- " <src-cdf-spec> <dst-cdf-spec>",
- " [/SINGLE or /MULTI] [/ROW or /COLUMN]",
- " [/HOST or /NETWORK]",
- #endif
- #if defined(unix)
- "Usage: % cdfconvert [-skeleton <cdf-path>] [-[no]log]",
- " <src-cdf-spec> <dst-cdf-spec>",
- " [-single or -multi] [-row or -column]",
- " [-host or -network]",
- #endif
- #if defined(__MSDOS__)
- "Usage: > cdfconvert [-skeleton <cdf-path>] [-[no]log]",
- " <src-cdf-spec> <dst-cdf-spec>",
- " [-single or -multi] [-row or -column]",
- " [-host or -network]",
- #endif
- "",
- "Purpose: CDFconvert is used to convert one or more CDFs. Conversions",
- " can be from older releases of CDF (eg. Version 1 CDFs) to the",
- " current release and/or to change the format, majority, or",
- " encoding.",
- "",
- "Parameter(s): <src-cdf-spec>",
- " The source CDF(s). This can be either a single CDF",
- " pathname or a directory/wildcard path in which case all",
- " CDFs which match the specification will be converted.",
- " Wildcards are allowed in the CDF name but not in the",
- " directory path. In either case, do not specify an",
- " extension.",
- "",
- " <dst-cdf-spec>",
- " The destination of the converted CDF(s). This may be a",
- " single CDF pathname only if {\tt <src-cdf-spec>} is a",
- " single CDF pathname. If the directory paths are the",
- " same, then a different CDF name must be specified. If",
- " more than one CDF is being converted, this must be a",
- " directory path (other than the source directory path).",
- " This may also be a directory path if only one CDF",
- " is being converted. In any case, do not specify an",
- " extension.",
- "",
- #if defined(vms)
- "Qualifier(s): /SKELETON=<cdf-path>",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- "Qualifier(s): -skeleton <cdf-path>",
- #endif
- " <cdf-path> is the pathname of a skeleton CDF to be used",
- " during the conversions (do not enter an extension). The",
- " skeleton CDF is used in the following cases.",
- "",
- " 1. If an assumed attribute scope is found in a source",
- " CDF, then the scope of that attribute in the skeleton",
- " CDF (if the attribute exists) will be used in the",
- " destination CDF.",
- "",
- " 2. If a format for the destination CDF(s) was not",
- " specified, then the format of the skeleton CDF will",
- " be used.",
- "",
- " 3. If a majority for the destination CDF(s) was not",
- " specified, then the majority of the skeleton CDF will",
- " be used.",
- "",
- " 4. If an encoding for the destination CDF(s) was not",
- " specified, then the encoding of the skeleton CDF will",
- " be used.",
- "",
- " Specifying a skeleton CDF is optional.",
- "",
- #if defined(vms)
- " /[NO]LOG",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -[no]log",
- #endif
- " Specifies whether or not messages are displayed",
- " indicating the progress of a conversion. The",
- " default is logging disabled.",
- "",
- #if defined(vms)
- " /SINGLE",
- " /MULTI",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -single",
- " -multi",
- #endif
- " The format of the destination CDF(s). This overrides the",
- " format of the skeleton CDF (if specified). If neither",
- " this qualifier nor a skeleton CDF is specified, then the",
- " format of the destination CDF(s) will be the same as that",
- " of the source CDF(s). (Optional).",
- "",
- #if defined(vms)
- " /ROW",
- " /COLUMN",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -row",
- " -column",
- #endif
- " The majority of the destination CDF(s). This overrides",
- " the majority of the skeleton CDF (if specified). If",
- " neither this qualifier nor a skeleton CDF is specified,",
- " then the majority of the destination CDF(s) will be the",
- " same as that of the source CDF(s). (Optional).",
- "",
- #if defined(vms)
- " /HOST",
- " /NETWORK",
- #endif
- #if defined(unix) | defined(__MSDOS__)
- " -host",
- " -network",
- #endif
- " The encoding of the destination CDF(s). This overrides",
- " the encoding of the skeleton CDF (if specified). If",
- " neither this qualifier nor a skeleton CDF is specified,",
- " then the encoding of the destination CDF(s) will be the",
- " same as that of the source CDF(s). (Optional).",
- "",
- #if defined(vms)
- "Example(s): $ CDFCONVERT CDF$SMPL:TPLATE0 TEMPLATE0X",
- " $ CDFCONVERT CDF$SMPL: USER_DISK:[USER.CDF]",
- " $ CDFCONVERT CAC_SST_BLENDED CAC_SST_BLENDEDX/SINGLE/NETWORK",
- " $ CDFCONVERT/SKELETON=CDF$SMPL:TPLATE3 CAC_SST_* [USER.CDF]",
- #endif
- #if defined(unix)
- "Example(s): % cdfconvert ../samples/tplate0 template0x",
- " % cdfconvert ../samples/ /disk4/user/cdf/",
- " % cdfconvert cac_sst_blended cac_sst_1 -single -network",
- " % cdfconvert -skeleton tplate3 '../cdf/cac_sst_*' ~user/cdf",
- #endif
- #if defined(__MSDOS__)
- "Example(s): > cdfconvert ..\\samples\\tplate0 tplate0x",
- " > cdfconvert ..\\samples c:\\disk4\\user\\cdf",
- " > cdfconvert cac_sst cac_sst1 -single -network",
- " > cdfconvert -skeleton tplate3 ..\\cac_sst* b:\\user\\cdf",
- #endif
- NULL };
-
- /******************************************************************************
- * main.
- ******************************************************************************/
-
- #if defined(vms)
- main (argc, argv)
- #else
- void main (argc, argv)
- #endif
- int argc;
- char *argv[];
- {
- QOP *qop;
- static char *validQuals[] = { "single", "multi", "row", "column",
- "host", "network", "skeleton",
- "log", "nolog", NULL };
- static int optRequired[] = { FALSE, FALSE, FALSE, FALSE,
- FALSE, FALSE, TRUE,
- FALSE, FALSE, 0 };
- CDFstatus status;
- char tempSpec[CDF_PATHNAME_LEN + 1];
- char srcSpec[CDF_PATHNAME_LEN + 1];
- char dstSpec[CDF_PATHNAME_LEN + 1];
- char srcPath[CDF_PATHNAME_LEN + 1];
- char dstPath[CDF_PATHNAME_LEN + 1];
- char sktPath[CDF_PATHNAME_LEN + 1];
- int count;
- long numCDFs;
- int i;
- char **directories;
- char **CDFnames;
-
- /******************************************************************************
- * Get qualifiers/options/parameters.
- ******************************************************************************/
-
- switch (argc) {
- case 1:
- PageInst (instructions);
- Exit;
- default:
- qop = Qop (argc, argv, validQuals, optRequired);
- if (qop == NULL) ExitBAD;
-
- switch (qop->Nparms) {
- case 0:
- case 1:
- printf ("Missing parameter(s).\n");
- ExitBAD;
- case 2:
- strcpy (srcSpec, qop->parms[0]);
- strcpy (dstSpec, qop->parms[1]);
- #if defined(vms) | defined(__MSDOS__)
- Upcase (srcSpec);
- Upcase (dstSpec);
- #endif
- break;
- default:
- printf ("Too many parameters.\n");
- ExitBAD;
- }
-
- /**************************************************************************
- * Open/inquire skeleton CDF before...
- **************************************************************************/
-
- if (qop->qualEntered[6]) {
- strcpy (sktPath, qop->qualOpt[6]);
- printf ("Opening Skeleton CDF: %s\n", sktPath);
- status = CDFlib (OPEN_, CDF_, sktPath, &sktId,
- GET_, CDF_FORMAT_, &dstFormat,
- CDF_MAJORITY_, &dstMajority,
- CDF_ENCODING_, &dstEncoding,
- NULL_);
- if (status < CDF_OK) {
- StatusHandler ("SKT", status);
- useSkeletonCDF = FALSE;
- }
- else
- useSkeletonCDF = TRUE;
- }
- else
- useSkeletonCDF = FALSE;
-
- /**************************************************************************
- * ...checking for an overriding format, majority, or encoding.
- **************************************************************************/
-
- count = 0;
- if (qop->qualEntered[0]) count++;
- if (qop->qualEntered[1]) count++;
- switch (count) {
- case 0:
- break; /* no override */
- case 1:
- if (qop->qualEntered[0])
- dstFormat = SINGLE_FILE;
- else
- dstFormat = MULTI_FILE;
- break;
- default:
- printf ("Conflicting qualifiers\n");
- ExitBAD;
- }
-
- count = 0;
- if (qop->qualEntered[2]) count++;
- if (qop->qualEntered[3]) count++;
- switch (count) {
- case 0:
- break; /* no override */
- case 1:
- if (qop->qualEntered[2])
- dstMajority = ROW_MAJOR;
- else
- dstMajority = COL_MAJOR;
- break;
- default:
- printf ("Conflicting qualifiers\n");
- ExitBAD;
- }
-
- count = 0;
- if (qop->qualEntered[4]) count++;
- if (qop->qualEntered[5]) count++;
- switch (count) {
- case 0:
- break; /* no override */
- case 1:
- if (qop->qualEntered[4])
- dstEncoding = HOST_ENCODING;
- else
- dstEncoding = NETWORK_ENCODING;
- break;
- default:
- printf ("Conflicting qualifiers\n");
- ExitBAD;
- }
-
- count = 0;
- if (qop->qualEntered[7]) count++;
- if (qop->qualEntered[8]) count++;
- switch (count) {
- case 0:
- mLog = FALSE;
- break;
- case 1:
- if (qop->qualEntered[7])
- mLog = TRUE;
- else
- mLog = FALSE;
- break;
- default:
- printf ("Conflicting qualifiers\n");
- ExitBAD;
- }
-
- break;
- }
-
- /******************************************************************************
- * Determine CDF(s) to convert.
- ******************************************************************************/
-
- strcpy (tempSpec, srcSpec);
- strcat (tempSpec, ".cdf");
-
- if ((! IsReg(tempSpec)) && (! IsDir(dstSpec))) {
- printf
- ("Source directory/wildcard specified, destination must be directory.\n");
- ExitBAD;
- }
-
- if (IsDir(srcSpec))
- AppendToDir (srcSpec, "*.cdf");
- else
- strcat (srcSpec, ".cdf");
-
- numCDFs = DirList (srcSpec, &directories, &CDFnames);
- if (numCDFs < 1) {
- fprintf(stderr, "No CDF(s) found in source directory.\n");
- ExitBAD;
- }
-
- RemoveExtensions (numCDFs, CDFnames);
-
- /******************************************************************************
- * Convert CDFs.
- ******************************************************************************/
-
- for (i = 0; i < numCDFs; i++) {
- /***************************************************************************
- * Build paths to open/display.
- ***************************************************************************/
-
- strcpy (srcPath, directories[i]);
- AppendToDir (srcPath, CDFnames[i]);
-
- strcpy (dstPath, dstSpec);
- if (IsDir(dstPath)) AppendToDir (dstPath, CDFnames[i]);
-
- ConvertCDF (srcPath, dstPath);
- }
-
- /******************************************************************************
- * Close skeleton CDF if one was used.
- ******************************************************************************/
-
- if (useSkeletonCDF) {
- status = CDFclose (sktId);
- StatusHandler ("STK", status); /* Ignore return. */
- }
-
- Exit;
- }
-
- /******************************************************************************
- * ConvertCDF.
- ******************************************************************************/
-
- Boolean ConvertCDF (srcPath, dstPath)
- char *srcPath;
- char *dstPath;
- {
- CDFstatus status;
- long format, majority, encoding;
-
- printf ("Converting \"%s\" to \"%s\"\n", srcPath, dstPath);
-
- /***************************************************************************
- * Open source CDF. If an error occurs, skip to next CDF.
- ***************************************************************************/
-
- status = CDFlib (OPEN_, CDF_, srcPath, &srcId,
- GET_, CDF_FORMAT_, &srcFormat,
- CDF_MAJORITY_, &srcMajority,
- CDF_ENCODING_, &srcEncoding,
- CDF_NUMDIMS_, &numDims,
- CDF_DIMSIZES_, dimSizes,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- /***************************************************************************
- * Determine format, majority, and encoding of destination CDF.
- ***************************************************************************/
-
- if (dstFormat == SOURCEformat)
- format = srcFormat;
- else
- format = dstFormat;
-
- if (dstMajority == SOURCEmajority)
- majority = srcMajority;
- else
- majority = dstMajority;
-
- if (dstEncoding == SOURCEencoding)
- encoding = srcEncoding;
- else
- encoding = dstEncoding;
-
- /***************************************************************************
- * Create destination CDF. If an error occurs, close source CDF and return.
- ***************************************************************************/
-
- status = CDFlib (CREATE_, CDF_, dstPath, numDims, dimSizes, &dstId,
- PUT_, CDF_FORMAT_, format,
- CDF_MAJORITY_, majority,
- CDF_ENCODING_, encoding,
- NULL_);
- if (! StatusHandler("DST",status)) {
- status = CDFclose (srcId);
- StatusHandler ("SRC", status);
- return FALSE;
- }
-
- /***************************************************************************
- * Convert attributes. If that is successful, convert variables.
- ***************************************************************************/
-
- if (! ConvertAttributes()) {
- status = CDFclose (srcId);
- StatusHandler ("SRC", status);
- status = CDFclose (dstId);
- StatusHandler ("DST", status);
- return FALSE;
- }
-
- /***************************************************************************
- * Convert variables.
- ***************************************************************************/
-
- if (! ConvertVariables (srcMajority, majority)) {
- status = CDFclose (srcId);
- StatusHandler ("SRC", status);
- status = CDFclose (dstId);
- StatusHandler ("DST", status);
- return FALSE;
- }
-
- /***************************************************************************
- * Close source and destination CDFs.
- ***************************************************************************/
-
- status = CDFclose (srcId);
- StatusHandler ("SRC", status); /* Ignore return. */
-
- status = CDFclose (dstId);
- StatusHandler ("DST", status); /* Ignore return. */
-
- /*****************************************************************************/
-
- return TRUE; /* Conversion successful. */
- }
-
- /******************************************************************************
- * ConvertAttributes.
- ******************************************************************************/
-
- Boolean ConvertAttributes ()
- {
- CDFstatus status;
- long attrNum, entryNum, ignoredNum;
- long numAttrs, maxEntry;
- long scope, dataType, numElements;
- long sktScope;
- char attrName[CDF_ATTR_NAME_LEN + 1];
- void *value;
-
- if (mLog) printf (" (converting attributes)\n");
-
- /******************************************************************************
- * Inquire number of attributes to be converted.
- ******************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, srcId,
- GET_, CDF_NUMATTRS_, &numAttrs,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- for (attrNum = 0; attrNum < numAttrs; attrNum++) {
- /***************************************************************************
- * Inquire attribute in source CDF.
- ***************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, srcId,
- ATTR_, attrNum,
- GET_, ATTR_NAME_, attrName,
- ATTR_SCOPE_, &scope,
- ATTR_MAXENTRY_, &maxEntry,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- /***************************************************************************
- * If an assumed scope, check if the scope from the skeleton CDF can be used.
- ***************************************************************************/
-
- if (scope == GLOBAL_SCOPE_ASSUMED || scope == VARIABLE_SCOPE_ASSUMED)
- if (useSkeletonCDF) {
- status = CDFlib (SELECT_, CDF_, sktId,
- ATTR_NAME_, attrName,
- GET_, ATTR_SCOPE_, &sktScope,
- NULL_);
- if (status != NO_SUCH_ATTR) {
- if (! StatusHandler("SKT",status)) return FALSE;
- scope = sktScope;
- }
- }
-
- /***************************************************************************
- * Create new attribute in destination CDF.
- ***************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, dstId,
- CREATE_, ATTR_, attrName, scope, &ignoredNum,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
-
- /***************************************************************************
- * Copy entries from source CDF to destination CDF.
- ***************************************************************************/
-
- for (entryNum = 0; entryNum <= maxEntry; entryNum++) {
- status = CDFlib (SELECT_, CDF_, srcId,
- ENTRY_, entryNum,
- GET_, ENTRY_DATATYPE_, &dataType,
- ENTRY_NUMELEMS_, &numElements,
- NULL_);
- if (status != NO_SUCH_ENTRY) {
- if (! StatusHandler("SRC",status)) return FALSE;
-
- MALLOC (value, ElemSize(dataType) * numElements);
-
- status = CDFlib (SELECT_, CDF_, srcId,
- GET_, ENTRY_DATA_, value,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, dstId,
- ENTRY_, entryNum,
- PUT_, ENTRY_DATA_, dataType, numElements, value,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
-
- free (value);
- }
- }
- }
-
- return TRUE; /* Success. */
- }
-
- /******************************************************************************
- * ConvertVariables.
- ******************************************************************************/
-
- Boolean ConvertVariables (SRCmajority, DSTmajority)
- long SRCmajority;
- long DSTmajority;
- {
- CDFstatus status;
- long numVars;
- long varNum, ignoredNum;
- long dataType, numElements;
- long recVary, dimVarys[CDF_MAX_DIMS];
- char varName[CDF_VAR_NAME_LEN + 1];
- long NrecValues, NvalueBytes, NrecBytes;
- long recNum, maxRec;
- long NextendRecs;
- long dimN, i;
- void *buffer;
- void *bufferX; /* Buffer with switched majority. */
- void *bufferZ;
- void *value;
- void *fillValue;
- enum flipENUM {noFLIP_,ROWtoCOL_,COLtoROW_} flip;
- enum accTypeENUM {HYP,SEQ,SIN} accType;
-
- static long HYPindices[CDF_MAX_DIMS] = {0,0,0,0,0,0,0,0,0,0};
- static long HYPcounts[CDF_MAX_DIMS];
- static long HYPintervals[CDF_MAX_DIMS] = {1,1,1,1,1,1,1,1,1,1};
-
- static long SEQindices[CDF_MAX_DIMS] = {0,0,0,0,0,0,0,0,0,0};
-
- static long SINcounts[CDF_MAX_DIMS];
- long indices[CDF_MAX_DIMS];
-
- if (mLog) printf (" (converting variables)\n");
-
- /******************************************************************************
- * Inquire number of variables to be converted.
- ******************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, srcId,
- GET_, CDF_NUMVARS_, &numVars,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- for (varNum = 0; varNum < numVars; varNum++) {
- /***************************************************************************
- * Inquire existing variable in source CDF.
- ***************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, srcId,
- VAR_, varNum,
- GET_, VAR_NAME_, varName,
- VAR_DATATYPE_, &dataType,
- VAR_NUMELEMS_, &numElements,
- VAR_RECVARY_, &recVary,
- VAR_DIMVARYS_, dimVarys,
- VAR_MAXREC_, &maxRec,
- VAR_EXTENDRECS_, &NextendRecs,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- /***************************************************************************
- * Creating new variable in destination CDF.
- ***************************************************************************/
-
- status = CDFlib (SELECT_, CDF_, dstId,
- CREATE_, VAR_, varName, dataType, numElements, recVary,
- dimVarys, &ignoredNum,
- PUT_, VAR_EXTENDRECS_, NextendRecs,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
-
- /***************************************************************************
- * Specify fill value for new variable (if it exists for old variable).
- ***************************************************************************/
-
- NvalueBytes = numElements * ElemSize(dataType);
- MALLOC (fillValue, NvalueBytes);
-
- status = CDFlib (SELECT_, CDF_, srcId,
- GET_, VAR_FILLVALUE_, fillValue,
- NULL_);
- if (status != NO_FILLVALUE_SPECIFIED) {
- if (! StatusHandler("SRC",status)) return FALSE;
- status = CDFlib (SELECT_, CDF_, dstId,
- PUT_, VAR_FILLVALUE_, fillValue,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
- }
-
- free (fillValue);
-
- /***************************************************************************
- * Calculate number of values/bytes per record.
- ***************************************************************************/
-
- NrecValues = 1;
-
- if (numDims > 0)
- for (dimN = 0; dimN < numDims; dimN++)
- if (dimVarys[dimN]) NrecValues *= dimSizes[dimN];
-
- NrecBytes = NrecValues * NvalueBytes;
-
- /***************************************************************************
- * Determine type of access.
- ***************************************************************************/
-
- switch (numDims) {
- case 0:
- accType = SEQ;
- MALLOC (value, NvalueBytes);
- break;
-
- case 1:
- #if defined(__MSDOS__)
- if (NrecBytes > (long) 65535) {
- accType = SEQ;
- MALLOC (value, NvalueBytes);
- }
- else {
- #endif
- buffer = (void *) malloc (NrecBytes);
- if (buffer == NULL) {
- accType = SEQ;
- MALLOC (value, NvalueBytes);
- }
- else {
- accType = HYP;
- flip = noFLIP_;
- }
- #if defined(__MSDOS__)
- }
- #endif
-
- break;
-
- default:
- #if defined(__MSDOS__)
- if (NrecBytes > (long) 65535) {
- if (SRCmajority == DSTmajority)
- accType = SEQ;
- else
- accType = SIN;
- MALLOC (value, NvalueBytes);
- }
- else {
- #endif
- buffer = (void *) malloc (NrecBytes);
- if (buffer != NULL)
- if (SRCmajority != DSTmajority) {
- bufferX = (void *) malloc (NrecBytes);
- if (bufferX != NULL) {
- accType = HYP;
- if (SRCmajority == ROW_MAJOR)
- flip = ROWtoCOL_;
- else
- flip = COLtoROW_;
- }
- else {
- free (buffer);
- accType = SIN;
- MALLOC (value, NvalueBytes);
- }
- }
- else {
- accType = HYP;
- flip = noFLIP_;
- }
- else {
- if (SRCmajority == DSTmajority)
- accType = SEQ;
- else
- accType = SIN;
- MALLOC (value, NvalueBytes);
- }
- #if defined(__MSDOS__)
- }
- #endif
- }
-
- /***************************************************************************
- * Convert each variable record.
- ***************************************************************************/
-
- switch (accType) {
- case HYP:
- /***********************************************************************
- * Use hyper reads/writes.
- ***********************************************************************/
-
- if (mLog) {
- printf (" (converting variable \"%s\" values with ", varName);
- printf ("hyper reads/writes)\n");
- }
-
- for (dimN = 0; dimN < numDims; dimN++)
- if (dimVarys[dimN])
- HYPcounts[dimN] = dimSizes[dimN];
- else
- HYPcounts[dimN] = 1;
-
- status = CDFlib (SELECT_, CDF_, srcId,
- CDF_RECCOUNT_, (long) 1,
- CDF_RECINTERVAL_, (long) 1,
- CDF_DIMINDICES_, HYPindices,
- CDF_DIMCOUNTS_, HYPcounts,
- CDF_DIMINTERVALS_, HYPintervals,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, dstId,
- CDF_RECCOUNT_, (long) 1,
- CDF_RECINTERVAL_, (long) 1,
- CDF_DIMINDICES_, HYPindices,
- CDF_DIMCOUNTS_, HYPcounts,
- CDF_DIMINTERVALS_, HYPintervals,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
-
- for (recNum = 0; recNum <= maxRec; recNum++) {
- status = CDFlib (SELECT_, CDF_, srcId,
- CDF_RECNUMBER_, recNum,
- GET_, VAR_HYPERDATA_, buffer,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- switch (flip) {
- case ROWtoCOL_:
- ROWtoCOL (buffer, bufferX, numDims, HYPcounts, NvalueBytes);
- bufferZ = bufferX;
- break;
- case COLtoROW_:
- COLtoROW (buffer, bufferX, numDims, HYPcounts, NvalueBytes);
- bufferZ = bufferX;
- break;
- case noFLIP_:
- bufferZ = buffer;
- break;
- }
-
- status = CDFlib (SELECT_, CDF_, dstId,
- CDF_RECNUMBER_, recNum,
- PUT_, VAR_HYPERDATA_, bufferZ,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
- }
-
- free (buffer);
- if (SRCmajority != DSTmajority) free (bufferX);
-
- break;
-
- case SEQ:
- /***********************************************************************
- * Use sequential reads/writes.
- ***********************************************************************/
-
- if (mLog) {
- printf (" (converting variable \"%s\" values with ", varName);
- printf ("sequential reads/writes)\n");
- }
-
- status = CDFlib (SELECT_, CDF_, srcId,
- VAR_SEQPOS_, (long) 0, SEQindices,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, dstId,
- VAR_SEQPOS_, (long) 0, SEQindices,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, srcId,
- GET_, VAR_SEQDATA_, value,
- NULL_);
- while (status >= CDF_OK) {
- status = CDFlib (SELECT_, CDF_, dstId,
- PUT_, VAR_SEQDATA_, value,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, srcId,
- GET_, VAR_SEQDATA_, value,
- NULL_);
- }
- if (status != END_OF_VAR)
- if (! StatusHandler("SRC",status)) return FALSE;
-
- free (value);
- break;
-
- case SIN:
- /***********************************************************************
- * Use Single reads/writes.
- ***********************************************************************/
-
- if (mLog) {
- printf (" (converting variable \"%s\" values with ", varName);
- printf ("single reads/writes)\n");
- }
-
- for (dimN = 0; dimN < numDims; dimN++)
- if (dimVarys[dimN])
- SINcounts[dimN] = dimSizes[dimN];
- else
- SINcounts[dimN] = 1;
-
- for (recNum = 0; recNum <= maxRec; recNum++) {
- for (dimN = 0; dimN < numDims; dimN++) indices[dimN] = 0;
-
- status = CDFlib (SELECT_, CDF_, srcId,
- CDF_RECNUMBER_, recNum,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, dstId,
- CDF_RECNUMBER_, recNum,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
-
- for (i = 0; i < NrecValues; i++) {
- status = CDFlib (SELECT_, CDF_, srcId,
- CDF_DIMINDICES_, indices,
- GET_, VAR_DATA_, value,
- NULL_);
- if (! StatusHandler("SRC",status)) return FALSE;
-
- status = CDFlib (SELECT_, CDF_, dstId,
- CDF_DIMINDICES_, indices,
- PUT_, VAR_DATA_, value,
- NULL_);
- if (! StatusHandler("DST",status)) return FALSE;
-
- if (SRCmajority == ROW_MAJOR) {
- INCRindicesROW (numDims, SINcounts, indices);
- }
- else {
- INCRindicesCOL (numDims, SINcounts, indices);
- }
- }
- }
-
- free (value);
-
- break;
- }
- }
-
- return TRUE; /* Success. */
- }
-
- /******************************************************************************
- * StatusHandler.
- ******************************************************************************/
-
- Boolean StatusHandler (which, status)
- char *which;
- CDFstatus status;
- {
- char text[CDF_STATUSTEXT_LEN + 1];
-
- if (status == CDF_OK) return TRUE; /* Do nothing. */
-
- CDFlib (SELECT_, CDF_STATUS_, status,
- GET_, STATUS_TEXT_, text,
- NULL_);
-
- if (status < CDF_WARN) {
- printf (" ERROR, %s> %s\n", which, text);
- return FALSE;
- }
- else {
- if (mLog)
- if (status < CDF_OK)
- printf (" WARNING, %s> %s\n", which, text);
- else
- printf (" INFO, %s> %s\n", which, text);
- return TRUE;
- }
- }
-